using System;
using System.Collections.Generic;
using System.Text;

using OWED.Network.Messages.General;
using System.Xml;

namespace OWED.Network.Messages
{
    class ApproveChange: IXmlAble
    {
        User my_user;
        DocName my_docname;
        ChangeID my_id;
        public ApproveChange(User user, DocName docName, ChangeID id)
        {
            my_user = user;
            my_docname = docName;
            my_id = id;
        }

        public User User { get { return my_user; } }
        public DocName DocName { get { return my_docname; } }
        public ChangeID ChangeID { get { return my_id; } }

        public static ApproveChange FromXml(XmlDocument xml)
        {
            XmlDocument doc = new XmlDocument();
            doc.AppendChild(
                doc.ImportNode(xml.SelectSingleNode("approveChange/User"), true));
            User user = User.FromXml(doc);

            doc = new XmlDocument();
            doc.AppendChild(
                doc.ImportNode(xml.
                                SelectSingleNode("approveChange/DocName"), true));
            DocName docname = DocName.FromXml(doc);

            doc = new XmlDocument();
            doc.AppendChild(
                doc.ImportNode(xml.
                            SelectSingleNode("approveChange/ChangeID"), true));
            ChangeID id = ChangeID.FromXml(doc);


            return new ApproveChange(user, docname, id);
        }

        public XmlNode ToXml()
        {
            XmlDocument doc = new XmlDocument();
            XmlNode node = doc.CreateElement("approveChange");
            doc.AppendChild(node);
            node.AppendChild(doc.ImportNode(my_user.ToXml(), true));
            node.AppendChild(doc.ImportNode(my_docname.ToXml(), true));
            node.AppendChild(doc.ImportNode(my_id.ToXml(), true));
            return doc;
        }
    }
}
